package procTest;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

import org.junit.Before;
import org.junit.Test;

import proc.BasicFileProcessor;
import proc.FileProcessor;

public class BasicFileProcessorTest {

	private File report;
	private File result;
	private Logger LOG;
	private FileProcessor fileProcTest;
	private final String path = "src/procTest/IOFiles/";

	@Before
	public void setUp() {
		this.LOG = Logger.getLogger("TestLog");
		this.report = new File(this.path + "report_output");
		this.result = new File(this.path + "result_output");
		this.report.delete();
		this.result.delete();
	}

	/**
	 * In the aux: input is empty
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxContentTest1() throws IOException {
		this.fileProcTest = new BasicFileProcessor(this.LOG);
		File auxFile = new File(this.path + "auxiliary_input_empty");
		assertEquals("Error doesn't recongnized.", 0,
				this.fileProcTest.processAuxFile(auxFile));
	}

	/**
	 * In the aux: is more than 2 lines
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxContentTest2() throws IOException {
		this.fileProcTest = new BasicFileProcessor(this.LOG);
		File auxFile = new File(this.path + "auxiliary_input_overlines");
		assertEquals("Error doesn't recongnized.", 0,
				this.fileProcTest.processAuxFile(auxFile));
	}

	/**
	 * In the aux: The first byte is non-positive
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxContentTest3() throws IOException {
		this.fileProcTest = new BasicFileProcessor(this.LOG);
		File auxFile = new File(this.path + "auxiliary_input_nonpos");
		assertEquals("Error doesn't recongnized.", 0,
				this.fileProcTest.processAuxFile(auxFile));
	}

	/**
	 * In the aux: The second line contains things other than one next-line
	 * marker
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxSLTest() throws IOException {
		this.fileProcTest = new BasicFileProcessor(this.LOG);
		File auxFile = new File(this.path + "auxiliary_input_secondline");
		assertEquals("Error doesn't recongnized.", 0,
				this.fileProcTest.processAuxFile(auxFile));
	}

	/**
	 * In the aux: The num_lines is large
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxExtTest1() throws IOException {
		this.fileProcTest = new BasicFileProcessor(this.LOG);
		File auxFile = new File(this.path + "auxiliary_input_large");
		assertEquals("Large auciliary input file cannot be processed.", 100,
				this.fileProcTest.processAuxFile(auxFile));
	}

	/**
	 * In the aux: The num_lines is extremely large
	 * 
	 * @throws IOException
	 */
	@Test
	public void auxExtTest2() throws IOException {
		this.fileProcTest = new BasicFileProcessor(this.LOG);
		File auxFile = new File(this.path + "auxiliary_input_extreme");
		assertEquals("Large auciliary input file cannot be processed.", 10000,
				this.fileProcTest.processAuxFile(auxFile));
	}

}
